package com.blb.educourseservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.common.entity.Course;
import com.blb.educourseservice.mapper.CourseMapper;
import com.blb.educourseservice.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> getAllCourses() {
        return courseMapper.selectAll();
    }

    @Override
    public Course getCourseById(Long id) {
        return courseMapper.selectById(id);
    }

    @Override
    public Course addCourseSales(Long id,Integer sales) {
        Course course = courseMapper.selectById(id);
        if(course != null){
            course.setSales(course.getSales() + sales);
            courseMapper.updateById(course);
        }
        return course;
    }
}
